package com.onePractice.spring.demo.controller;

import com.onePractice.spring.demo.model.UserInfo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/resp")
//@RestController
@Controller
public class RespController {
    @RequestMapping("/r1")
    public String returnPage() {
        return "/index.html";
    }

    @RequestMapping("/r2")
    @ResponseBody
    public String returnData() {
        return "我是前端需要的数据";
    }

    @RequestMapping("/r3")
    @ResponseBody
    public String returnHTML() {
        return "<h1>我是一级标题</h1>";
    }

    @RequestMapping(value = "/r4",produces = "text/plain")
    @ResponseBody
    public String returnText() {
        return "<h1>我是一级标题</h1>";
    }

    @RequestMapping(value = "/r5")
    @ResponseBody
    public UserInfo returnJson() {
        UserInfo userInfo = new UserInfo("zhangsan",1,1);
        return userInfo;
    }

    @RequestMapping(value = "/r6")
    @ResponseBody
    public UserInfo setStatus(HttpServletResponse response) {
        response.setStatus(401);
        UserInfo userInfo = new UserInfo("zhangsan",1,1);
        return userInfo;
    }

    @RequestMapping(value = "/r7")
    @ResponseBody
    public String setHeader(HttpServletResponse response) {
        response.setHeader("myHeader","myHeader");
        return "设置Header成功";
    }
}
